home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / dflt18.arj / MESSAGE.C < prev    next >
Text File  |  1994-03-12  |  19KB  |  643 lines

  1. /* --------- message.c ---------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static int px = -1, py = -1;
  6. static int pmx = -1, pmy = -1;
  7. static int mx, my;
  8. static int handshaking = 0;
  9. static BOOL CriticalError;
  10. BOOL AllocTesting = FALSE;
  11. jmp_buf AllocError;
  12. BOOL AltDown = FALSE;
  13.  
  14. /* ---------- event queue ---------- */
  15. static struct events    {
  16.     MESSAGE event;
  17.     int mx;
  18.     int my;
  19. } EventQueue[MAXMESSAGES];
  20.  
  21. /* ---------- message queue --------- */
  22. static struct msgs {
  23.     WINDOW wnd;
  24.     MESSAGE msg;
  25.     PARAM p1;
  26.     PARAM p2;
  27. } MsgQueue[MAXMESSAGES];
  28.  
  29. static int EventQueueOnCtr;
  30. static int EventQueueOffCtr;
  31. static int EventQueueCtr;
  32.  
  33. static int MsgQueueOnCtr;
  34. static int MsgQueueOffCtr;
  35. static int MsgQueueCtr;
  36.  
  37. static int lagdelay = FIRSTDELAY;
  38.  
  39. static void (interrupt far *oldtimer)(void);
  40. static void (interrupt far *oldkeyboard)(void);
  41.  
  42. static int keyportvalue;    /* for watching for key release */
  43.  
  44. WINDOW CaptureMouse;
  45. WINDOW CaptureKeyboard;
  46. static BOOL NoChildCaptureMouse;
  47. static BOOL NoChildCaptureKeyboard;
  48.  
  49. static int doubletimer = -1;
  50. static int delaytimer  = -1;
  51. static int clocktimer  = -1;
  52.  
  53. static WINDOW Cwnd;
  54.  
  55. static void interrupt far newkeyboard(void)
  56. {
  57.     keyportvalue = inp(KEYBOARDPORT);
  58.     oldkeyboard();
  59. }
  60.  
  61. /* ------- timer interrupt service routine ------- */
  62. static void interrupt far newtimer(void)
  63. {
  64.     if (timer_running(doubletimer))
  65.         countdown(doubletimer);
  66.     if (timer_running(delaytimer))
  67.         countdown(delaytimer);
  68.     if (timer_running(clocktimer))
  69.         countdown(clocktimer);
  70.     oldtimer();
  71. }
  72.  
  73. static char ermsg[] = "Error accessing drive x";
  74.  
  75. /* -------- test for critical errors --------- */
  76. int TestCriticalError(void)
  77. {
  78.     int rtn = 0;
  79.     if (CriticalError)    {
  80.         rtn = 1;
  81.         CriticalError = FALSE;
  82.         if (TestErrorMessage(ermsg) == FALSE)
  83.             rtn = 2;
  84.     }
  85.     return rtn;
  86. }
  87.  
  88. /* ------ critical error interrupt service routine ------ */
  89. static void interrupt far newcrit(IREGS ir)
  90. {
  91.     if (!(ir.ax & 0x8000))     {
  92.         ermsg[sizeof(ermsg) - 2] = (ir.ax & 0xff) + 'A';
  93.         CriticalError = TRUE;
  94.     }
  95.     ir.ax = 0;
  96. }
  97.  
  98. static void StopMsg(void)
  99. {
  100.     if (oldtimer != NULL)    {
  101.         setvect(TIMER, oldtimer);
  102.         oldtimer = NULL;
  103.     }
  104.     if (oldkeyboard != NULL)    {
  105.         setvect(KEYBOARDVECT, oldkeyboard);
  106.         oldkeyboard = NULL;
  107.     }
  108.     ClearClipboard();
  109.     ClearDialogBoxes();
  110.     restorecursor();    
  111.     unhidecursor();
  112.     hide_mousecursor();
  113. }
  114.  
  115. /* ------------ initialize the message system --------- */
  116. BOOL init_messages(void)
  117. {
  118.     AllocTesting = TRUE;
  119.     if (setjmp(AllocError) != 0)    {
  120.         StopMsg();
  121.         return FALSE;
  122.     }
  123.     resetmouse();
  124.     set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
  125.     savecursor();
  126.     hidecursor();
  127.     px = py = -1;
  128.     pmx = pmy = -1;
  129.     mx = my = 0;
  130.     CaptureMouse = CaptureKeyboard = NULL;
  131.     NoChildCaptureMouse = FALSE;
  132.     NoChildCaptureKeyboard = FALSE;
  133.     MsgQueueOnCtr = MsgQueueOffCtr = MsgQueueCtr = 0;
  134.     EventQueueOnCtr = EventQueueOffCtr = EventQueueCtr = 0;
  135.     if (oldtimer == NULL)    {
  136.         oldtimer = getvect(TIMER);
  137.         setvect(TIMER, newtimer);
  138.     }
  139.     if (oldkeyboard == NULL)    {
  140.         oldkeyboard = getvect(KEYBOARDVECT);
  141.         setvect(KEYBOARDVECT, newkeyboard);
  142.     }
  143.     setvect(CRIT, newcrit);
  144.     PostMessage(NULL,START,0,0);
  145.     lagdelay = FIRSTDELAY;
  146.     return TRUE;
  147. }
  148.  
  149. /* ----- post an event and parameters to event queue ---- */
  150. static void PostEvent(MESSAGE event, int p1, int p2)
  151. {
  152.     if (EventQueueCtr != MAXMESSAGES)    {
  153.         EventQueue[EventQueueOnCtr].event = event;
  154.         EventQueue[EventQueueOnCtr].mx = p1;
  155.         EventQueue[EventQueueOnCtr].my = p2;
  156.         if (++EventQueueOnCtr == MAXMESSAGES)
  157.             EventQueueOnCtr = 0;
  158.         EventQueueCtr++;
  159.     }
  160. }
  161.  
  162. /* ------ collect mouse, clock, and keyboard events ----- */
  163. static void near collect_events(void)
  164. {
  165.     static int ShiftKeys = 0;
  166.     int sk;
  167.     struct tm *now;
  168.     static BOOL flipflop = FALSE;
  169.     static char timestr[9];
  170.     int hr;
  171.  
  172.     /* -------- test for a clock event (one/second) ------- */
  173.     if (timed_out(clocktimer))    {
  174.         /* ----- get the current time ----- */
  175.         time_t t = time(NULL);
  176.         now = localtime(&t);
  177.         hr = now->tm_hour > 12 ?
  178.              now->tm_hour - 12 :
  179.              now->tm_hour;
  180.         if (hr == 0)
  181.             hr = 12;
  182.         sprintf(timestr, "%2d:%02d", hr, now->tm_min);
  183.         strcpy(timestr+5, now->tm_hour > 11 ? "pm " : "am ");
  184.         /* ------- blink the : at one-second intervals ----- */
  185.         if (flipflop)
  186.             *(timestr+2) = ' ';
  187.         flipflop ^= TRUE;
  188.         /* -------- reset the timer -------- */
  189.         set_timer(clocktimer, 1);
  190.         /* -------- post the clock event -------- */
  191.         PostEvent(CLOCKTICK, FP_SEG(timestr), FP_OFF(timestr));
  192.     }
  193.  
  194.     /* --------- keyboard events ---------- */
  195.     if ((sk = getshift()) != ShiftKeys)    {
  196.         ShiftKeys = sk;
  197.         /* ---- the shift status changed ---- */
  198.         PostEvent(SHIFT_CHANGED, sk, 0);
  199.         if (sk & ALTKEY)
  200.             AltDown = TRUE;
  201.     }
  202.  
  203.     /* ---- build keyboard events for key combinations that
  204.         BIOS doesn't report --------- */
  205.     if (sk & ALTKEY)    {
  206.         if (keyportvalue == 14)    {
  207.             AltDown = FALSE;
  208.             waitforkeyboard();
  209.             PostEvent(KEYBOARD, ALT_BS, sk);
  210.         }
  211.         if (keyportvalue == 83)    {
  212.             AltDown = FALSE;
  213.             waitforkeyboard();
  214.             PostEvent(KEYBOARD, ALT_DEL, sk);
  215.         }
  216.     }
  217.     if (sk & CTRLKEY)    {
  218.         AltDown = FALSE;
  219.         if (keyportvalue == 82)    {
  220.             waitforkeyboard();
  221.             PostEvent(KEYBOARD, CTRL_INS, sk);
  222.         }
  223.     }
  224.     /* ----------- test for keystroke ------- */
  225.     if (keyhit())    {
  226.         static int cvt[] = {SHIFT_INS,END,DN,PGDN,BS,'5',
  227.                         FWD,HOME,UP,PGUP};
  228.         int c = getkey();
  229.  
  230.         AltDown = FALSE;
  231.         /* -------- convert numeric pad keys ------- */
  232.         if (sk & (LEFTSHIFT | RIGHTSHIFT))    {
  233.             if (c >= '0' && c <= '9')
  234.                 c = cvt[c-'0'];
  235.             else if (c == '.' || c == DEL)
  236.                 c = SHIFT_DEL;
  237.             else if (c == INS)
  238.                 c = SHIFT_INS;
  239.         }
  240.         if (c != '\r' && (c < ' ' || c > 127))
  241.             clearBIOSbuffer();
  242.         /* ------ post the keyboard event ------ */
  243.         PostEvent(KEYBOARD, c, sk);
  244.     }
  245.  
  246.     /* ------------ test for mouse events --------- */
  247.     if (button_releases())    {
  248.         /* ------- the button was released -------- */
  249.         AltDown = FALSE;
  250.         doubletimer = DOUBLETICKS;
  251.         PostEvent(BUTTON_RELEASED, mx, my);
  252.         disable_timer(delaytimer);
  253.     }
  254.     get_mouseposition(&mx, &my);
  255.     if (mx != px || my != py)  {
  256.         px = mx;
  257.         py = my;
  258.         PostEvent(MOUSE_MOVED, mx, my);
  259.     }
  260.     if (rightbutton())    {
  261.         AltDown = FALSE;
  262.         PostEvent(RIGHT_BUTTON, mx, my);
  263.     }
  264.     if (leftbutton())    {
  265.         AltDown = FALSE;
  266.         if (mx == pmx && my == pmy)    {
  267.             /* ---- same position as last left button ---- */
  268.             if (timer_running(doubletimer))    {
  269.                 /* -- second click before double timeout -- */
  270.                 disable_timer(doubletimer);
  271.                 PostEvent(DOUBLE_CLICK, mx, my);
  272.             }
  273.             else if (!timer_running(delaytimer))    {
  274.                 /* ---- button held down a while ---- */
  275.                 delaytimer = lagdelay;
  276.                 lagdelay = DELAYTICKS;
  277.                 /* ---- post a typematic-like button ---- */
  278.                 PostEvent(LEFT_BUTTON, mx, my);
  279.             }
  280.         }
  281.         else    {
  282.             /* --------- new button press ------- */
  283.             disable_timer(doubletimer);
  284.             delaytimer = FIRSTDELAY;
  285.             lagdelay = DELAYTICKS;
  286.             PostEvent(LEFT_BUTTON, mx, my);
  287.             pmx = mx;
  288.             pmy = my;
  289.         }
  290.     }
  291.     else
  292.         lagdelay = FIRSTDELAY;
  293. }
  294.  
  295. /* ----- post a message and parameters to msg queue ---- */
  296. void PostMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  297. {
  298.     if (MsgQueueCtr != MAXMESSAGES)    {
  299.         MsgQueue[MsgQueueOnCtr].wnd = wnd;
  300.         MsgQueue[MsgQueueOnCtr].msg = msg;
  301.         MsgQueue[MsgQueueOnCtr].p1 = p1;
  302.         MsgQueue[MsgQueueOnCtr].p2 = p2;
  303.         if (++MsgQueueOnCtr == MAXMESSAGES)
  304.             MsgQueueOnCtr = 0;
  305.         MsgQueueCtr++;
  306.     }
  307. }
  308.  
  309. /* --------- send a message to a window ----------- */
  310. int SendMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  311. {
  312.     int rtn = TRUE, x, y;
  313.  
  314. #ifdef INCLUDE_LOGGING
  315.     LogMessages(wnd, msg, p1, p2);
  316. #endif
  317.     if (wnd != NULL)
  318.         switch (msg)    {
  319.             case PAINT:
  320.             case BORDER:
  321.                 /* ------- don't send these messages unless the
  322.                     window is visible -------- */
  323.                 if (isVisible(wnd))
  324.                     rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  325.                 break;
  326.             case RIGHT_BUTTON:
  327.             case LEFT_BUTTON:
  328.             case DOUBLE_CLICK:
  329.             case BUTTON_RELEASED:
  330.                 /* --- don't send these messages unless the
  331.                     window is visible or has captured the mouse -- */
  332.                 if (isVisible(wnd) || wnd == CaptureMouse)
  333.                     rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  334.                 break;
  335.             case KEYBOARD:
  336.             case SHIFT_CHANGED:
  337.                 /* ------- don't send these messages unless the
  338.                     window is visible or has captured the keyboard -- */
  339.                 if (!(isVisible(wnd) || wnd == CaptureKeyboard))
  340.                     break;
  341.             default:
  342.                 rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  343.                 break;
  344.         }
  345.     /* ----- window processor returned true or the message was sent
  346.         to no window at all (NULL) ----- */
  347.     if (rtn != FALSE)    {
  348.         /* --------- process messages that a window sends to the
  349.             system itself ---------- */
  350.         switch (msg)    {
  351.             case STOP:
  352.                 StopMsg();
  353.                 break;
  354.             /* ------- clock messages --------- */
  355.             case CAPTURE_CLOCK:
  356.                 Cwnd = wnd;
  357.                 set_timer(clocktimer, 0);
  358.                 break;
  359.             case RELEASE_CLOCK:
  360.                 Cwnd = NULL;
  361.                 disable_timer(clocktimer);
  362.                 break;
  363.             /* -------- keyboard messages ------- */
  364.             case KEYBOARD_CURSOR:
  365.                 if (wnd == NULL)
  366.                     cursor((int)p1, (int)p2);
  367.                 else if (wnd == inFocus)
  368.                     cursor(GetClientLeft(wnd)+(int)p1,
  369.                                 GetClientTop(wnd)+(int)p2);
  370.                 break;
  371.             case CAPTURE_KEYBOARD:
  372.                 if (p2)
  373.                     ((WINDOW)p2)->PrevKeyboard=CaptureKeyboard;
  374.                 else
  375.                     wnd->PrevKeyboard = CaptureKeyboard;
  376.                 CaptureKeyboard = wnd;
  377.                 NoChildCaptureKeyboard = (int)p1;
  378.                 break;
  379.             case RELEASE_KEYBOARD:
  380.                 if (wnd != NULL)    {
  381.                     if (CaptureKeyboard == wnd || (int)p1)
  382.                         CaptureKeyboard = wnd->PrevKeyboard;
  383.                     else    {
  384.                         WINDOW twnd = CaptureKeyboard;
  385.                         while (twnd != NULL)    {
  386.                             if (twnd->PrevKeyboard == wnd)    {
  387.                                 twnd->PrevKeyboard = wnd->PrevKeyboard;
  388.                                 break;
  389.                             }
  390.                             twnd = twnd->PrevKeyboard;
  391.                         }
  392.                         if (twnd == NULL)
  393.                             CaptureKeyboard = NULL;
  394.                     }
  395.                     wnd->PrevKeyboard = NULL;
  396.                 }
  397.                 else
  398.                     CaptureKeyboard = NULL;
  399.                 NoChildCaptureKeyboard = FALSE;
  400.                 break;
  401.             case CURRENT_KEYBOARD_CURSOR:
  402.                 curr_cursor(&x, &y);
  403.                 *(int*)p1 = x;
  404.                 *(int*)p2 = y;
  405.                 break;
  406.             case SAVE_CURSOR:
  407.                 savecursor();
  408.                 break;
  409.             case RESTORE_CURSOR:
  410.                 restorecursor();
  411.                 break;
  412.             case HIDE_CURSOR:
  413.                 normalcursor();
  414.                 hidecursor();
  415.                 break;
  416.             case SHOW_CURSOR:
  417.                 if (p1)
  418.                     set_cursor_type(0x0106);
  419.                 else
  420.                     set_cursor_type(0x0607);
  421.                 unhidecursor();
  422.                 break;
  423.             case WAITKEYBOARD:
  424.                 waitforkeyboard();
  425.                 break;
  426.             /* -------- mouse messages -------- */
  427.             case RESET_MOUSE:
  428.                 resetmouse();
  429.                 set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
  430.                 break;
  431.             case MOUSE_INSTALLED:
  432.                 rtn = mouse_installed();
  433.                 break;
  434.             case MOUSE_TRAVEL:    {
  435.                 RECT rc;
  436.                 if (!p1)    {
  437.                     rc.lf = rc.tp = 0;
  438.                     rc.rt = SCREENWIDTH-1;
  439.                     rc.bt = SCREENHEIGHT-1;
  440.                 }
  441.                 else 
  442.                     rc = *(RECT *)p1;
  443.                 set_mousetravel(rc.lf, rc.rt, rc.tp, rc.bt);
  444.                 break;
  445.             }
  446.             case SHOW_MOUSE:
  447.                 show_mousecursor();
  448.                 break;
  449.             case HIDE_MOUSE:
  450.                 hide_mousecursor();
  451.                 break;
  452.             case MOUSE_CURSOR:
  453.                 set_mouseposition((int)p1, (int)p2);
  454.                 break;
  455.             case CURRENT_MOUSE_CURSOR:
  456.                 get_mouseposition((int*)p1,(int*)p2);
  457.                 break;
  458.             case WAITMOUSE:
  459.                 waitformouse();
  460.                 break;
  461.             case TESTMOUSE:
  462.                 rtn = mousebuttons();
  463.                 break;
  464.             case CAPTURE_MOUSE:
  465.                 if (p2)
  466.                     ((WINDOW)p2)->PrevMouse = CaptureMouse;
  467.                 else
  468.                     wnd->PrevMouse = CaptureMouse;
  469.                 CaptureMouse = wnd;
  470.                 NoChildCaptureMouse = (int)p1;
  471.                 break;
  472.             case RELEASE_MOUSE:
  473.                 if (wnd != NULL)    {
  474.                     if (CaptureMouse == wnd || (int)p1)
  475.                         CaptureMouse = wnd->PrevMouse;
  476.                     else    {
  477.                         WINDOW twnd = CaptureMouse;
  478.                         while (twnd != NULL)    {
  479.                             if (twnd->PrevMouse == wnd)    {
  480.                                 twnd->PrevMouse = wnd->PrevMouse;
  481.                                 break;
  482.                             }
  483.                             twnd = twnd->PrevMouse;
  484.                         }
  485.                         if (twnd == NULL)
  486.                             CaptureMouse = NULL;
  487.                     }
  488.                     wnd->PrevMouse = NULL;
  489.                 }
  490.                 else
  491.                     CaptureMouse = NULL;
  492.                 NoChildCaptureMouse = FALSE;
  493.                 break;
  494.             default:
  495.                 break;
  496.         }
  497.     }
  498.     return rtn;
  499. }
  500.  
  501. static RECT VisibleRect(WINDOW wnd)
  502. {
  503.     RECT rc = WindowRect(wnd);
  504.     if (!TestAttribute(wnd, NOCLIP))    {
  505.         WINDOW pwnd = GetParent(wnd);
  506.         RECT prc;
  507.         prc = ClientRect(pwnd);
  508.         while (pwnd != NULL)    {
  509.             if (TestAttribute(pwnd, NOCLIP))
  510.                 break;
  511.             rc = subRectangle(rc, prc);
  512.             if (!ValidRect(rc))
  513.                 break;
  514.             if ((pwnd = GetParent(pwnd)) != NULL)
  515.                 prc = ClientRect(pwnd);
  516.         }
  517.     }
  518.     return rc;
  519. }
  520.  
  521. /* ----- find window that mouse coordinates are in --- */
  522. static WINDOW inWindow(WINDOW wnd, int x, int y)
  523. {
  524.     WINDOW Hit = NULL;
  525.     while (wnd != NULL)    {
  526.         if (isVisible(wnd))    {
  527.             WINDOW wnd1;
  528.             RECT rc = VisibleRect(wnd);
  529.             if (InsideRect(x, y, rc))
  530.                 Hit = wnd;
  531.             if ((wnd1 = inWindow(LastWindow(wnd), x, y)) != NULL)
  532.                 Hit = wnd1;
  533.             if (Hit != NULL)
  534.                 break;
  535.         }
  536.         wnd = PrevWindow(wnd);
  537.     }
  538.     return Hit;
  539. }
  540.  
  541. static WINDOW MouseWindow(int x, int y)
  542. {
  543.     /* ------ get the window in which a
  544.                     mouse event occurred ------ */
  545.     WINDOW Mwnd = inWindow(ApplicationWindow, x, y);
  546.     /* ---- process mouse captures ----- */
  547.     if (CaptureMouse != NULL)    {
  548.         if (NoChildCaptureMouse ||
  549.                 Mwnd == NULL     ||
  550.                     !isAncestor(Mwnd, CaptureMouse))
  551.             Mwnd = CaptureMouse;
  552.     }
  553.     return Mwnd;
  554. }
  555.  
  556. void handshake(void)
  557. {
  558.     handshaking++;
  559.     dispatch_message();
  560.     --handshaking;
  561. }
  562.  
  563. /* ---- dispatch messages to the message proc function ---- */
  564. BOOL dispatch_message(void)
  565. {
  566.     WINDOW Mwnd, Kwnd;
  567.     /* -------- collect mouse and keyboard events ------- */
  568.     collect_events();
  569.     /* --------- dequeue and process events -------- */
  570.     while (EventQueueCtr > 0)  {
  571.         struct events ev;
  572.             
  573.         ev = EventQueue[EventQueueOffCtr];
  574.         if (++EventQueueOffCtr == MAXMESSAGES)
  575.             EventQueueOffCtr = 0;
  576.         --EventQueueCtr;
  577.  
  578.         /* ------ get the window in which a
  579.                         keyboard event occurred ------ */
  580.         Kwnd = inFocus;
  581.  
  582.         /* ---- process keyboard captures ----- */
  583.         if (CaptureKeyboard != NULL)
  584.             if (Kwnd == NULL ||
  585.                     NoChildCaptureKeyboard ||
  586.                         !isAncestor(Kwnd, CaptureKeyboard))
  587.                 Kwnd = CaptureKeyboard;
  588.  
  589.         /* -------- send mouse and keyboard messages to the
  590.             window that should get them -------- */
  591.         switch (ev.event)    {
  592.             case SHIFT_CHANGED:
  593.             case KEYBOARD:
  594.                 if (!handshaking)
  595.                     SendMessage(Kwnd, ev.event, ev.mx, ev.my);
  596.                 break;
  597.             case LEFT_BUTTON:
  598.                 if (!handshaking)    {
  599.                     Mwnd = MouseWindow(ev.mx, ev.my);
  600.                     if (!CaptureMouse ||
  601.                             (!NoChildCaptureMouse &&
  602.                                 isAncestor(Mwnd, CaptureMouse)))
  603.                         if (Mwnd != inFocus)
  604.                             SendMessage(Mwnd, SETFOCUS, TRUE, 0);
  605.                     SendMessage(Mwnd, LEFT_BUTTON, ev.mx, ev.my);
  606.                 }
  607.                 break;
  608.             case BUTTON_RELEASED:
  609.             case DOUBLE_CLICK:
  610.             case RIGHT_BUTTON:
  611.                 if (handshaking)
  612.                     break;
  613.             case MOUSE_MOVED:
  614.                 Mwnd = MouseWindow(ev.mx, ev.my);
  615.                 SendMessage(Mwnd, ev.event, ev.mx, ev.my);
  616.                 break;
  617.             case CLOCKTICK:
  618.                 SendMessage(Cwnd, ev.event,
  619.                     (PARAM) MK_FP(ev.mx, ev.my), 0);
  620.                 break;
  621.             default:
  622.                 break;
  623.         }
  624.     }
  625.     /* ------ dequeue and process messages ----- */
  626.     while (MsgQueueCtr > 0)  {
  627.         struct msgs mq;
  628.  
  629.         mq = MsgQueue[MsgQueueOffCtr];
  630.         if (++MsgQueueOffCtr == MAXMESSAGES)
  631.             MsgQueueOffCtr = 0;
  632.         --MsgQueueCtr;
  633.         SendMessage(mq.wnd, mq.msg, mq.p1, mq.p2);
  634.         if (mq.msg == ENDDIALOG)
  635.             return FALSE;
  636.         if (mq.msg == STOP)
  637.             return FALSE;
  638.     }
  639.     return TRUE;
  640. }
  641.  
  642. 
  643.